//
//  PrefsController.m
//  kismet-frontend
//
//  Created by L. Preston Sego III on 7/20/09.
//  Copyright 2009 Precognition Inc.. All rights reserved.
//

#import "PrefsController.h"


@implementation PrefsController

-(void)awakeFromNib
{    
    [prefsWindow makeKeyAndOrderFront:nil];
    [prefsWindow center];
    
    //Load default view
    [self showDrivers:nil];
    
}

-(void)showDrivers:(id)sender
{
    [prefsWindow setContentView:prefsDrivers];
    currentView = prefsDrivers;
    [self updateUI];
}

-(void)showKismetServer:(id)sender
{
    [prefsWindow setContentView:prefsServer];
    currentView = prefsServer;
    [self updateUI];
}

-(void)showKismetDrones:(id)sender
{
    [prefsWindow setContentView:prefsDrones];
    currentView = prefsDrones;
    [self updateUI];
}

-(void)updateUI 
// this is suppossed to resize to the each subview... but doesn't...
// pretty sure it has to do with the definition of controlBosFrame
// the width and heights are reporting the width and heights of their
// parent object.. which isn't what we need.
{
    NSView *contentView;
    NSRect controlBoxFrame;
    NSRect windowFrame;
    int newWindowHeight;
    NSRect newWindowFrame;
            
    contentView = [prefsWindow contentView];
    controlBoxFrame = NSMakeRect(0, 0, [currentView bounds].size.width, [currentView bounds].size.height);
    
    
    windowFrame = [NSWindow contentRectForFrameRect:[prefsWindow frame] styleMask:[prefsWindow styleMask]];
    newWindowHeight = NSHeight(controlBoxFrame) + 12;
    newWindowHeight += 43; //Constant for NSToolbarSizeModeRegular
    newWindowFrame = [NSWindow frameRectForContentRect:NSMakeRect(NSMinX(windowFrame), 
                                                                  NSMaxY(windowFrame) - newWindowHeight, 
                                                                  NSWidth(windowFrame), 
                                                                  newWindowHeight) 
                                             styleMask:[prefsWindow styleMask]];
   
    [prefsWindow setFrame:newWindowFrame 
                  display:YES 
                  animate:[prefsWindow isVisible]];    
    
    
    // this makes it so our subviews don't try to move around on us
    [currentView setFrameOrigin:NSMakePoint(floor((NSWidth([contentView frame]) - NSWidth(controlBoxFrame)) / 2.0),
                                           floor(NSHeight([contentView frame]) - NSHeight(controlBoxFrame)))];
    
}

@end
